<?php

namespace Log;

class LogHandlerManager {
	private $handlers = array();

	private function get ($handlerClass) {
		$key = $handlerClass->getName();
		
		if (!isset($this->handlers[$key]))
			$this->handlers[$key] = $handlerClass->newInstance();

		return $this->handlers[$key];
	}
	
	public function getHandler ($id) {
		$handlerClass = new \ReflectionClass('\Log\Handler\\'.$id);
		
		if (!$handlerClass->isSubclassOf('\Log\LogHandler'))
			throw new Exception("$id is not a subclass of \Log\LogHandler");

		return $this->get($handlerClass);
	}
}
